package com.justnow.offer;

/**
 * @author justnow
 * Created on 2020-09-18
 * Description
 */
public class Solution52_1 {
    public static void main(String[] args) {

    }
}

class UnionFind {
    int[] parents;
    int count;
    public UnionFind(int n) {
        count = n;
        for (int i = 0; i < n; i++) {
            parents[i] = i;
        }
    }
    public int find(int x) {
        while (parents[x] != x) {
            x = parents[x];
        }
        return x;
    }

    public void union(int x, int y) {
        int rootx = find(x);
        int rooty = find(y);
        if (rootx == rooty) {
            return;
        }
        parents[rootx] = rooty;
        count--;
    }
}
